﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using LowLevelGraphics;
using LowLevelGraphics.Filter;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// Rounds colors. 
    /// </summary>
    public class ActionRoundColor : AbstractCommand
    {
        protected byte m_nValue = 0;

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionRoundColor"/> class.
        /// </summary>
        /// <param name="_nValue">The _n value.</param>
        public ActionRoundColor(byte _nValue) 
        {
            m_nValue = _nValue;
        }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public byte Value
        {
            get { return m_nValue; }
            set { m_nValue = value; }
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            Bitmap bitmap = (Bitmap)MainFormSingleton.ActivePictureBox.BackgroundImage;
            UnsafeBitmap unsafeBitmap = new RoundColors(m_nValue).Execute(bitmap); //ImageFilters.RoundColors(bitmap, m_nValue);
            unsafeBitmap.Dispose();
        }
    }
}
